﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LeadMaster.Models;
using LeadMaster.DAL;

namespace LeadMaster.Controllers
{
    public class LeadMonitorController : Controller
    {
        private DunsmoreContext db = new DunsmoreContext();

        //
        // GET: /LeadMonitor/

        public ActionResult Index()
        {
            var leadmonitor = db.LeadMonitor.Include(l => l.Lead);
            return View(leadmonitor.ToList());
        }

        //
        // GET: /LeadMonitor/Details/5

        public ActionResult Details(int id = 0)
        {
            LeadMonitor leadmonitor = db.LeadMonitor.Find(id);
            if (leadmonitor == null)
            {
                return HttpNotFound();
            }
            return View(leadmonitor);
        }

        //
        // GET: /LeadMonitor/Create

        public ActionResult Create()
        {
            ViewBag.LeadID = new SelectList(db.Leads, "LeadID", "ContactType");
            return View();
        }

        //
        // POST: /LeadMonitor/Create

        [HttpPost]
        public ActionResult Create(LeadMonitor leadmonitor)
        {
            if (ModelState.IsValid)
            {
                db.LeadMonitor.Add(leadmonitor);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.LeadID = new SelectList(db.Leads, "LeadID", "ContactType", leadmonitor.LeadID);
            return View(leadmonitor);
        }

        //
        // GET: /LeadMonitor/Edit/5

        public ActionResult Edit(int id = 0)
        {
            LeadMonitor leadmonitor = db.LeadMonitor.Find(id);
            if (leadmonitor == null)
            {
                return HttpNotFound();
            }
            ViewBag.LeadID = new SelectList(db.Leads, "LeadID", "ContactType", leadmonitor.LeadID);
            return View(leadmonitor);
        }

        //
        // POST: /LeadMonitor/Edit/5

        [HttpPost]
        public ActionResult Edit(LeadMonitor leadmonitor)
        {
            if (ModelState.IsValid)
            {
                db.Entry(leadmonitor).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.LeadID = new SelectList(db.Leads, "LeadID", "ContactType", leadmonitor.LeadID);
            return View(leadmonitor);
        }

        //
        // GET: /LeadMonitor/Delete/5

        public ActionResult Delete(int id = 0)
        {
            LeadMonitor leadmonitor = db.LeadMonitor.Find(id);
            if (leadmonitor == null)
            {
                return HttpNotFound();
            }
            return View(leadmonitor);
        }

        //
        // POST: /LeadMonitor/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            LeadMonitor leadmonitor = db.LeadMonitor.Find(id);
            db.LeadMonitor.Remove(leadmonitor);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}